﻿using Admin.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace Admin.DAL
{
    public class ProductDAL:ConnectionDB
    {
        public List<ProductModel> SANPHAM(string id)
        {
            List<ProductModel> list = new List<ProductModel>();
            SqlCommand command = CreateCommand("select * from SANPHAM");

            SqlDataReader dr;
            dr = command.ExecuteReader();
            while (dr.Read())
            {
                ProductModel pro = new ProductModel();

                pro.MASP = dr["MASP"].ToString();
                pro.TENSP = dr["TENSP"].ToString();
                pro.GIA = dr["GIA"].ToString();

                list.Add(pro);
            }
            Connection.Close();
            return list;
        }
        public List<ProductModel> deletePR(string id)
        {
            List<ProductModel> list = new List<ProductModel>();
            SqlCommand command = CreateCommand("select * from SANPHAM where MASP='" + id + "'");
            SqlDataReader dr = command.ExecuteReader();
            while (dr.Read() == true)
            {
                ProductModel pr = new ProductModel();

                pr.MASP = dr["MASP"].ToString();
                pr.TENSP = dr["TENSP"].ToString();
                pr.GIA = dr["GIA"].ToString();
                list.Add(pr);
            }
            Connection.Close();
            return list;
        }

        public List<ProductModel> editPR(string id)
        {
            List<ProductModel> list = new List<ProductModel>();
            SqlCommand command = CreateCommand("select * from SANPHAM where MASP='" + id + "'");
            SqlDataReader dr = command.ExecuteReader();
            while (dr.Read() == true)
            {
                ProductModel pr = new ProductModel();

                pr.MASP = dr["MASP"].ToString();
                pr.TENSP = dr["TENSP"].ToString();
                pr.GIA = dr["GIA"].ToString();
                list.Add(pr);
            }
            Connection.Close();
            return list;
        }

        

        
    }
}